/**
 * Created by caoyang on 17/3/28.
 */

import React, { Component } from 'react';
import {
    AsyncStorage,
} from 'react-native';

import { Provider } from 'react-redux';
import App from './containers/App';
import store from './store/store';

import UserDefaults from './utils/UserDefaults';


export default class Root extends Component {

    render() {
        return (
            <Provider store={store}>
                <App />
            </Provider>
        )
    }

    componentDidMount() {

        // AsyncStorage RN自带的数据持久化技术
        var keyValuePairs = [['username', this.props.username], ['password', this.props.password]]
        AsyncStorage.multiSet(keyValuePairs, function(errs){
            if(errs) { return; }
        });

        // 登录信息保存
        // iOS 通过沙盒保存数据 NSUserDefaults
        var loginInfo = {username: this.props.username, password: this.props.password};
        UserDefaults.setObject(loginInfo, 'loginInfo');
    }
}

